home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / gamesa / frmgame.frm (.txt) < prev    next >
Visual Basic Form  |  1999-08-01  |  9KB  |  374 lines

  1. VERSION 5.00
  2. Begin VB.Form frmGame 
  3.    AutoRedraw      =   -1  'True
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "Tic Tac Toe"
  6.    ClientHeight    =   5175
  7.    ClientLeft      =   1470
  8.    ClientTop       =   330
  9.    ClientWidth     =   4410
  10.    BeginProperty Font 
  11.       Name            =   "MS Sans Serif"
  12.       Size            =   9.75
  13.       Charset         =   0
  14.       Weight          =   700
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    Icon            =   "frmGame.frx":0000
  20.    KeyPreview      =   -1  'True
  21.    LinkTopic       =   "Form1"
  22.    MaxButton       =   0   'False
  23.    MinButton       =   0   'False
  24.    Moveable        =   0   'False
  25.    ScaleHeight     =   273.19
  26.    ScaleMode       =   0  'User
  27.    ScaleWidth      =   223.858
  28.    ShowInTaskbar   =   0   'False
  29.    StartUpPosition =   2  'CenterScreen
  30.    Begin VB.Line Line1 
  31.       X1              =   0
  32.       X2              =   223.858
  33.       Y1              =   225.679
  34.       Y2              =   225.679
  35.    End
  36.    Begin VB.Line Line2 
  37.       X1              =   0
  38.       X2              =   223.097
  39.       Y1              =   232.014
  40.       Y2              =   232.014
  41.    End
  42.    Begin VB.Label Label1 
  43.       AutoSize        =   -1  'True
  44.       Caption         =   "Enter Cell Number (1-9)"
  45.       Height          =   240
  46.       Left            =   998
  47.       TabIndex        =   0
  48.       Top             =   4650
  49.       Width           =   2415
  50.    End
  51. Attribute VB_Name = "frmGame"
  52. Attribute VB_GlobalNameSpace = False
  53. Attribute VB_Creatable = False
  54. Attribute VB_PredeclaredId = True
  55. Attribute VB_Exposed = False
  56. Option Explicit
  57. Dim Reply
  58. Dim aa
  59. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  60. Dim CellVal As Integer
  61. CellVal = Val(Chr(KeyCode))
  62. If CellVal < 1 Or CellVal > 9 Then GoTo subgo
  63. If Cell(CellVal) = " " Then
  64. Cell(CellVal) = "X"
  65. Turn = 1 - Turn
  66. End If
  67. subgo:
  68. End Sub
  69. Private Sub Form_Load()
  70. Dim i
  71. aa = 0
  72. For i = 1 To 9
  73. Cell(i) = " "
  74. Next i
  75. frmGame.Width = 4500
  76. frmGame.Height = 5550
  77. frmGame.ScaleWidth = 300
  78. frmGame.ScaleHeight = 370
  79. DrawWidth = 3
  80. End Sub
  81. Public Sub Game()
  82. Lines
  83. Moves
  84. check
  85. If aa <> 0 Then Win
  86. If Turn = 1 Then CompMove
  87. End Sub
  88. Public Sub Lines()
  89. frmGame.Cls
  90. Line (0, 100)-(300, 100), RGB(0, 0, 255)
  91. Line (0, 200)-(300, 200), RGB(0, 0, 255)
  92. Line (100, 0)-(100, 300), RGB(0, 0, 255)
  93. Line (200, 0)-(200, 300), RGB(0, 0, 255)
  94. End Sub
  95. Public Sub Moves()
  96. If Cell(1) = " " Then
  97. PSet (50, 50), BackColor
  98. Print "1"
  99. End If
  100. If Cell(1) = "X" Then
  101. Line (10, 10)-(90, 90), RGB(255, 0, 0)
  102. Line (10, 90)-(90, 10), RGB(255, 0, 0)
  103. End If
  104. If Cell(1) = "O" Then
  105. Circle (50, 50), 40, RGB(0, 255, 0)
  106. End If
  107. If Cell(2) = " " Then
  108. PSet (150, 50), BackColor
  109. Print "2"
  110. End If
  111. If Cell(2) = "X" Then
  112. Line (110, 10)-(190, 90), RGB(255, 0, 0)
  113. Line (110, 90)-(190, 10), RGB(255, 0, 0)
  114. End If
  115. If Cell(2) = "O" Then
  116. Circle (150, 50), 40, RGB(0, 255, 0)
  117. End If
  118. If Cell(3) = " " Then
  119. PSet (250, 50), BackColor
  120. Print "3"
  121. End If
  122. If Cell(3) = "X" Then
  123. Line (210, 90)-(290, 10), RGB(255, 0, 0)
  124. Line (210, 10)-(290, 90), RGB(255, 0, 0)
  125. End If
  126. If Cell(3) = "O" Then
  127. Circle (250, 50), 40, RGB(0, 255, 0)
  128. End If
  129. If Cell(4) = " " Then
  130. PSet (50, 150), BackColor
  131. Print "4"
  132. End If
  133. If Cell(4) = "X" Then
  134. Line (10, 110)-(90, 190), RGB(255, 0, 0)
  135. Line (10, 190)-(90, 110), RGB(255, 0, 0)
  136. End If
  137. If Cell(4) = "O" Then
  138. Circle (50, 150), 40, RGB(0, 255, 0)
  139. End If
  140. If Cell(5) = " " Then
  141. PSet (150, 150), BackColor
  142. Print "5"
  143. End If
  144. If Cell(5) = "X" Then
  145. Line (110, 110)-(190, 190), RGB(255, 0, 0)
  146. Line (110, 190)-(190, 110), RGB(255, 0, 0)
  147. End If
  148. If Cell(5) = "O" Then
  149. Circle (150, 150), 40, RGB(0, 255, 0)
  150. End If
  151. If Cell(6) = " " Then
  152. PSet (250, 150), BackColor
  153. Print "6"
  154. End If
  155. If Cell(6) = "X" Then
  156. Line (210, 110)-(290, 190), RGB(255, 0, 0)
  157. Line (210, 190)-(290, 110), RGB(255, 0, 0)
  158. End If
  159. If Cell(6) = "O" Then
  160. Circle (250, 150), 40, RGB(0, 255, 0)
  161. End If
  162. If Cell(7) = " " Then
  163. PSet (50, 250), BackColor
  164. Print "7"
  165. End If
  166. If Cell(7) = "X" Then
  167. Line (10, 210)-(90, 290), RGB(255, 0, 0)
  168. Line (10, 290)-(90, 210), RGB(255, 0, 0)
  169. End If
  170. If Cell(7) = "O" Then
  171. Circle (50, 250), 40, RGB(0, 255, 0)
  172. End If
  173. If Cell(8) = " " Then
  174. PSet (150, 250), BackColor
  175. Print "8"
  176. End If
  177. If Cell(8) = "X" Then
  178. Line (110, 210)-(190, 290), RGB(255, 0, 0)
  179. Line (110, 290)-(190, 210), RGB(255, 0, 0)
  180. End If
  181. If Cell(8) = "O" Then
  182. Circle (150, 250), 40, RGB(0, 255, 0)
  183. End If
  184. If Cell(9) = " " Then
  185. PSet (250, 250), BackColor
  186. Print "9"
  187. End If
  188. If Cell(9) = "X" Then
  189. Line (210, 210)-(290, 290), RGB(255, 0, 0)
  190. Line (210, 290)-(290, 210), RGB(255, 0, 0)
  191. End If
  192. If Cell(9) = "O" Then
  193. Circle (250, 250), 40, RGB(0, 255, 0)
  194. End If
  195. End Sub
  196. Public Sub check()
  197. Dim i As Integer
  198. Dim Tied
  199. Dim a1, a2, a3, a4, a5, a6, a7, a8
  200. Tied = 0
  201. For i = 1 To 9
  202. If Cell(i) = "X" Then Add(i) = 1
  203. If Cell(i) = " " Then Add(i) = 0: Tied = 1
  204. If Cell(i) = "O" Then Add(i) = -1
  205. Next i
  206. If Tied = 0 Then
  207. MsgBox "Game Tied", vbExclamation + vbOKOnly
  208. End If
  209. a1 = Add(1) + Add(2) + Add(3)
  210. a2 = Add(4) + Add(5) + Add(6)
  211. a3 = Add(7) + Add(8) + Add(9)
  212. a4 = Add(1) + Add(4) + Add(7)
  213. a5 = Add(2) + Add(5) + Add(8)
  214. a6 = Add(3) + Add(6) + Add(9)
  215. a7 = Add(1) + Add(5) + Add(9)
  216. a8 = Add(3) + Add(5) + Add(7)
  217. If a1 = 3 Or a1 = -3 Then
  218. Line (0, 50)-(300, 50), RGB(255, 255, 255)
  219. aa = a1
  220. End If
  221. If a2 = 3 Or a2 = -3 Then
  222. Line (0, 150)-(300, 150), RGB(255, 255, 255)
  223. aa = a2
  224. End If
  225. If a3 = 3 Or a3 = -3 Then
  226. Line (0, 250)-(300, 250), RGB(255, 255, 255)
  227. aa = a3
  228. End If
  229. If a4 = 3 Or a4 = -3 Then
  230. Line (50, 0)-(50, 300), RGB(255, 255, 255)
  231. aa = a4
  232. End If
  233. If a5 = 3 Or a5 = -3 Then
  234. Line (150, 0)-(150, 300), RGB(255, 255, 255)
  235. aa = a5
  236. End If
  237. If a6 = 3 Or a6 = -3 Then
  238. Line (250, 0)-(250, 300), RGB(255, 255, 255)
  239. aa = a6
  240. End If
  241. If a7 = 3 Or a7 = -3 Then
  242. Line (0, 0)-(300, 300), RGB(255, 255, 255)
  243. aa = a7
  244. End If
  245. If a8 = 3 Or a8 = -3 Then
  246. Line (0, 300)-(300, 0), RGB(255, 255, 255)
  247. aa = a8
  248. End If
  249. End Sub
  250. Public Sub Win()
  251. If aa = 3 Then MsgBox "User Wins", vbExclamation + vbOKOnly
  252. If aa = -3 Then MsgBox "Computer Wins", vbExclamation + vbOKOnly
  253. Unload frmGame
  254. frmMain.Show 1
  255. End Sub
  256. Public Sub CompMove()
  257. Dim i As Integer
  258. Dim b1, b2, b3, b4, b5, b6, b7, b8, bb
  259. For i = 1 To 9
  260. If Cell(i) = "X" Then Ad(i) = 1
  261. If Cell(i) = " " Then Ad(i) = 0
  262. If Cell(i) = "O" Then Ad(i) = -1
  263. Next i
  264. b1 = Ad(1) + Ad(2) + Ad(3)
  265. b2 = Ad(4) + Ad(5) + Ad(6)
  266. b3 = Ad(7) + Ad(8) + Ad(9)
  267. b4 = Ad(1) + Ad(4) + Ad(7)
  268. b5 = Ad(2) + Ad(5) + Ad(8)
  269. b6 = Ad(3) + Ad(6) + Ad(9)
  270. b7 = Ad(1) + Ad(5) + Ad(9)
  271. b8 = Ad(3) + Ad(5) + Ad(7)
  272. If b1 = 2 Or b1 = -2 Then
  273. If Ad(1) = 0 Then Cell(1) = "O"
  274. If Ad(2) = 0 Then Cell(2) = "O"
  275. If Ad(3) = 0 Then Cell(3) = "O"
  276. Turn = 1 - Turn
  277. GoTo tosub
  278. End If
  279. If b2 = 2 Or b2 = -2 Then
  280. If Ad(4) = 0 Then Cell(4) = "O"
  281. If Ad(5) = 0 Then Cell(5) = "O"
  282. If Ad(6) = 0 Then Cell(6) = "O"
  283. Turn = 1 - Turn
  284. GoTo tosub
  285. End If
  286. If b3 = 2 Or b3 = -2 Then
  287. If Ad(7) = 0 Then Cell(7) = "O"
  288. If Ad(8) = 0 Then Cell(8) = "O"
  289. If Ad(9) = 0 Then Cell(9) = "O"
  290. Turn = 1 - Turn
  291. GoTo tosub
  292. End If
  293. If b4 = 2 Or b4 = -2 Then
  294. If Ad(1) = 0 Then Cell(1) = "O"
  295. If Ad(4) = 0 Then Cell(4) = "O"
  296. If Ad(7) = 0 Then Cell(7) = "O"
  297. Turn = 1 - Turn
  298. GoTo tosub
  299. End If
  300. If b5 = 2 Or b5 = -2 Then
  301. If Ad(2) = 0 Then Cell(2) = "O"
  302. If Ad(5) = 0 Then Cell(5) = "O"
  303. If Ad(8) = 0 Then Cell(8) = "O"
  304. Turn = 1 - Turn
  305. GoTo tosub
  306. End If
  307. If b6 = 2 Or b6 = -2 Then
  308. If Ad(3) = 0 Then Cell(3) = "O"
  309. If Ad(9) = 0 Then Cell(9) = "O"
  310. If Ad(6) = 0 Then Cell(6) = "O"
  311. Turn = 1 - Turn
  312. GoTo tosub
  313. End If
  314. If b7 = 2 Or b7 = -2 Then
  315. If Ad(1) = 0 Then Cell(1) = "O"
  316. If Ad(5) = 0 Then Cell(5) = "O"
  317. If Ad(9) = 0 Then Cell(9) = "O"
  318. Turn = 1 - Turn
  319. GoTo tosub
  320. End If
  321. If b8 = 2 Or b8 = -2 Then
  322. If Ad(7) = 0 Then Cell(7) = "O"
  323. If Ad(5) = 0 Then Cell(5) = "O"
  324. If Ad(3) = 0 Then Cell(3) = "O"
  325. Turn = 1 - Turn
  326. GoTo tosub
  327. End If
  328. If Cell(5) = " " Then
  329. Cell(5) = "O"
  330. Turn = 1 - Turn
  331. GoTo tosub
  332. End If
  333. If Cell(1) = " " Then
  334. Cell(1) = "O"
  335. Turn = 1 - Turn
  336. GoTo tosub
  337. End If
  338. If Cell(3) = " " Then
  339. Cell(3) = "O"
  340. Turn = 1 - Turn
  341. GoTo tosub
  342. End If
  343. If Cell(7) = " " Then
  344. Cell(7) = "O"
  345. Turn = 1 - Turn
  346. GoTo tosub
  347. End If
  348. If Cell(9) = " " Then
  349. Cell(9) = "O"
  350. Turn = 1 - Turn
  351. GoTo tosub
  352. End If
  353. If Cell(8) = " " Then
  354. Cell(8) = "O"
  355. Turn = 1 - Turn
  356. GoTo tosub
  357. End If
  358. If Cell(2) = " " Then
  359. Cell(2) = "O"
  360. Turn = 1 - Turn
  361. GoTo tosub
  362.